package com.zrf.testchatgpt.jwt;

import com.zrf.testchatgpt.shiro.realm.JwtRealm;
import com.zrf.testchatgpt.shiro.realm.LoginRealm;
import org.apache.shiro.authz.Authorizer;
import org.apache.shiro.authz.ModularRealmAuthorizer;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.subject.PrincipalCollection;

public class MyCustomerAuthrizer extends ModularRealmAuthorizer {
    @Override
    public boolean isPermitted(PrincipalCollection principals, String permission) {
        assertRealmsConfigured();

        for (Realm realm : getRealms()) {
            if (!(realm instanceof Authorizer)) continue;
            //做一个类型判断
//            if (realm instanceof JwtRealm) {
//                return ((JwtRealm) realm).isPermitted(principals, permission);
//            }
            if (realm instanceof LoginRealm){
                return ((LoginRealm) realm).isPermitted(principals, permission);
            }
        }
        return false;
    }
}
